<template>

    <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="单据编码">
            <el-input v-model="formInline.documentNumber" placeholder="单据编码" clearable />
        </el-form-item>
        <el-form-item label="客户名称">
            <el-input v-model="formInline.customerProfileName" placeholder="客户名称" clearable />
        </el-form-item>
        <el-form-item label="销售员">
            <el-input v-model="formInline.salesStaff" placeholder="销售员" clearable />
            <!-- <el-select v-model="formInline.salesStaff" placeholder="请选择" clearable style="width: 150px;">
                <el-option v-for="item in material" :key="item.materialTypeId" :label="item.materialTypeName"
                    :value="item.materialTypeId" />
            </el-select> -->
        </el-form-item>
        <el-form-item label="单据状态">
            <el-select v-model="formInline.documentStatus" placeholder="请选择" clearable style="width: 150px;">
                <el-option :lable="'开立'" value="开立"></el-option>
                <el-option :lable="'审核'" value="审核"></el-option>
                <el-option :lable="'退回'" value="退回"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="业务状态">
            <el-select v-model="formInline.businessStatus" placeholder="请选择" clearable style="width: 150px;">
                <el-option :lable="'正常'" value="正常"></el-option>
                <el-option :lable="'挂起'" value="挂起"></el-option>
                <el-option :lable="'手工关闭'" value="手工关闭"></el-option>
                <el-option :lable="'系统关闭'" value="系统关闭"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="GetSuppliers()">搜索</el-button>
        </el-form-item>


    </el-form>
    <el-button type="primary" :icon="List" @click="GetSuppliers1()">查询所有</el-button>
    <el-button type="primary" :icon="List" @click="router.push('/SalesOrderListShow')">明细</el-button>
    <el-button type="primary" :icon="Plus" plain @click="router.push('/SalesOrderAddView')">新增</el-button>
    <el-button type="primary" :icon="Plus" disabled="true" plain>审核</el-button>
    <el-button type="primary" :icon="Plus" disabled="true" plain>反审核</el-button>
    <el-button type="primary" :icon="Download">导入</el-button>
    <el-button type="primary" :icon="Upload">导出</el-button>


    <el-empty description="暂无数据" v-show="suppliers.length == 0" />
    <el-table :data="suppliers" stripe style="width: 100%" v-show="suppliers.length != 0">
        <el-table-column prop="documentNumber" label="单据编码" />
        <el-table-column prop="documentDate" label="单据日期">
            <template #default="scope">
                {{ scope.row.documentDate == null ? "" : scope.row.documentDate.substring(0, 10) }}
            </template>
        </el-table-column>
        <el-table-column prop="documentStatus" label="单据状态" />
        <el-table-column prop="customerProfileName" label="客户名称" />
        <el-table-column prop="salesStaff" label="销售员" />
        <el-table-column prop="businessStatus" label="业务状态" />
        <el-table-column prop="auditDate" label="审核时间">
            <template #default="scope">
                {{ scope.row.auditDate == null ? "" : scope.row.auditDate.substring(0, 10) }}
            </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="140">
            <template #default="scope">
                <el-button link type="primary" size="small"
                    @click="router.push('/SalesOrderEditView?id=' + scope.row.documentNumber)">查看</el-button>
                <el-button link type="danger" size="small" disabled="true">删除</el-button>
                <el-button link type="success" size="small" disabled="true">编辑</el-button>
            </template>
        </el-table-column>
    </el-table>

    <div>
        <tr>
            <td>
                <el-pagination v-model:current-page="formInline.pageIndex" v-model:page-size="formInline.pageSize"
                    :page-sizes="[10, 20, 30, 40, 50]" :background="true" layout="total, slot, prev, pager, next"
                    :total="formInline.totalCount" @size-change="handleSizeChange"
                    @current-change="handleCurrentChange">
                </el-pagination>
            </td>
            <td>
                <el-pagination v-model:current-page="formInline.pageIndex" v-model:page-size="formInline.pageSize"
                    :page-sizes="[10, 20, 30, 40, 50]" :background="true" layout="slot, sizes, jumper"
                    :total="formInline.totalCount" @size-change="handleSizeChange"
                    @current-change="handleCurrentChange">
                </el-pagination>
            </td>
        </tr>
    </div>
</template>

<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { useRoute } from 'vue-router'
import axios from 'axios';
import { Plus, Download, Upload, List } from '@element-plus/icons-vue'
import type { TabsPaneContext } from 'element-plus'
const cpiurls = import.meta.env.VITE_APP_API_URL_SalesManagementCommon;//5227
const router = useRouter()
const route = useRoute()

onMounted(() => {
    GetSuppliers()
});

const formInline = reactive({
    documentNumber: '',
    customerProfileName: '',
    salesStaff: '',
    businessStatus: '',
    documentStatus: '',
    pageIndex: 1,
    pageSize: 10,
    pageCount: 0,
    totalCount: 0,

})


const handleClick = (tab: TabsPaneContext, event: Event) => {
    console.log(tab, event)
}
//销售订单单据列表
const suppliers: any = ref([]);
const GetSuppliers = () => {
    axios
        .get(
            cpiurls + '/api/SalesOrder/QuerySalesOrder',
            {
                params: {
                    documentNumber: formInline.documentNumber,
                    businessStatus: formInline.businessStatus,
                    salesStaff: formInline.salesStaff,
                    customerProfileName: formInline.customerProfileName,
                    documentStatus: formInline.documentStatus,
                    pageIndex: formInline.pageIndex,
                    pageSize: formInline.pageSize,
                }
            }
        )
        .then((res) => {
            console.log(res.data.data);
            suppliers.value = res.data.data;
            formInline.pageCount = res.data.pageCount;
            formInline.totalCount = res.data.totalCount;
        })
        .catch((err) => {
            console.log(err);
        });
};

const GetSuppliers1 = () => {
    axios
        .get(
            cpiurls + '/api/SalesOrder/SearchSalesOrderDetail',
            {
                params: {
                    documentNumber: '',
                    businessStatus: '',
                    salesStaff: '',
                    customerProfileName: '',
                    documentStatus: '',
                    pageIndex: 1,
                    pageSize: 10,
                }
            }
        )
        .then((res) => {
            console.log(res.data.data);
            suppliers.value = res.data.data;
            formInline.pageCount = res.data.pageCount;
            formInline.totalCount = res.data.totalCount;
        })
        .catch((err) => {
            console.log(err);
        });
};

//分页
const handleSizeChange = (val: number) => {
    formInline.pageSize = val
    GetSuppliers()
}
const handleCurrentChange = (val: number) => {
    formInline.pageIndex = val
    GetSuppliers()
}



const formLabelWidth = '140px'

</script>

<style>
.demo-tabs>.el-tabs__content {
    padding: 32px;
    color: #6b778c;
    font-size: 32px;
    font-weight: 600;
}
</style>